package com.shawn.spring.boot.mybatis.util;

import com.shawn.spring.boot.mybatis.constants.BaseEnum;

/**
 * @author shawn
 * @since 2020/8/30
 */
public class EnumUtil {

  public static <E extends Enum<?> & BaseEnum> E codeOf(Class<E> enumClass, int code) {
    E[] es = enumClass.getEnumConstants();
    for (E e : es) {
      if (code == e.getCode()) {
        return e;
      }
    }
    return null;
  }
}
